package com.lovo.csc.controller;



import com.lovo.csc.entity.Frozen;
import com.lovo.csc.entity.Maintain;
import com.lovo.csc.entity.Register;
import com.lovo.csc.service.IFrozenService;
import com.lovo.csc.service.IMaintainService;
import com.lovo.csc.service.IRegisterService;
import com.lovo.dto.FrozenDto;
import com.lovo.dto.RegisterDto;
import com.lovo.remoteservice.ICommodityService;
import com.lovo.sscsys.remoteService.IsscsysRemoteService;
import com.lovo.util.MQUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lovo
 * @since 2022-07-07
 */
@RestController
@Api(tags = "客户维护，谢兴茂")
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    IRegisterService registerService;

    @Autowired
    IMaintainService maintainService;
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    IFrozenService service;
    @Autowired
    ICommodityService commodityService;

    @GetMapping("findAll")
    @ApiOperation(value = "查询客户注册信息")
    public List<Register> findAll(){

        List<Register> findAll = registerService.list();
        return  findAll;
    }
    @GetMapping("findhou")
    @ApiOperation(value = "查询冻结客户信息")
    public List<Frozen> findhou(){
        List<Frozen> maintains=service.list();
        return maintains;
    }

    @DeleteMapping("del")
    public boolean del(int id){
        registerService.removeById(id);
        return true;
    }
    @GetMapping("tong/{name}/{code}/{reason}/{level}")
    public boolean tong(@PathVariable("name") String name,@PathVariable("code") int code,
                        @PathVariable("reason") String reason,@PathVariable("level") String level){
        commodityService.setAuditStatus(name,code,reason,level);
        return true;
    }


    @GetMapping("save/{id}")
    public boolean save(@PathVariable("id") int id){
     Register register = registerService.getById(id);
      Maintain maintain = new Maintain();
        maintain.setMGrade(register.getRGrade());
            maintain.setMCompany(register.getRCompany());
            maintain.setMShimg(register.getRShimg());
            maintain.setMZiimg(register.getRZiimg());
            maintain.setMRealname(register.getRRealname());
            maintain.setMGender(register.getRGender());
            maintain.setMPhone(register.getRPhone());
            maintain.setMPwd(register.getRPwd());
            maintain.setMName(register.getRName());
        maintainService.save(maintain);

        FrozenDto frozenDto=new FrozenDto();
        frozenDto.setRealName(maintain.getMRealname());
        frozenDto.setUserCard(maintain.getMShimg());
        frozenDto.setUserName(maintain.getMName());
        frozenDto.setUserPwd(maintain.getMPwd());
        frozenDto.setUserSex(maintain.getMGender());
        frozenDto.setUserQualification(maintain.getMZiimg());
        frozenDto.setUserPompany(maintain.getMCompany());
        frozenDto.setUserPhone(maintain.getMPhone());
        frozenDto.setGrade(maintain.getMGrade());

        if(frozenDto!=null){
            rabbitTemplate.convertAndSend(MQUtil.houExchange,MQUtil.houKey,frozenDto);
            this.del(id);
            return true;
        }
        return false;
    }


    @GetMapping("gai")
    public boolean gai(String usrName,int State,String reason){
        commodityService.setAuditStatus(usrName,State,reason,"LV0");
        return true;
    }






}